<?php
session_start();

require_once 'OAuth/Consumer.php';

$options = array(
    'requestScheme' => OAuth::REQUEST_SCHEME_HEADER,
    'version' => '1.0', // there is only a 1.0 version for now ;)
    'signatureMethod' => 'HMAC-SHA1',
    'localUrl' => 'http://path/to/this/file.php', // change to this file's local URL
    'requestTokenUrl' => 'http://ma.gnolia.com/oauth/get_request_token',
    'userAuthorisationUrl' => 'http://ma.gnolia.com/oauth/authorize',
    'accessTokenUrl' => 'http://ma.gnolia.com/oauth/get_access_token',
);

// replace with your own real application consumer key and key secret!
$consumer = new OAuth_Consumer('CONSUMER_KEY', 'CONSUMER_KEY_SECRET', $options);

if (!isset($_SESSION['ACCESS_TOKEN'])) {
    if (!empty($_GET)) {
        $token = $consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN']));
        $_SESSION['ACCESS_TOKEN'] = serialize($token);
    } else {
        $token = $consumer->getRequestToken();
        $_SESSION['REQUEST_TOKEN'] = serialize($token);
        $consumer->redirect();
        exit;
    }
} else {
    $token = unserialize($_SESSION['ACCESS_TOKEN']);
    $_SESSION['ACCESS_TOKEN'] = null;
}

$methodUrl = 'http://ma.gnolia.com/api/rest/2/bookmarks_count';
$rawData = $token->toQueryString($methodUrl, $consumer, array('group'=>'oauth'));
$client = new HTTP_Request;
$client->setURL($methodUrl);
$client->setMethod(HTTP_REQUEST_METHOD_POST);
$client->setRawPostData($rawData);

$client->sendRequest();
header('Content-Type: ' . $client->getResponseHeader('Content-Type'));
echo $client->getResponseBody();